<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8"%>
<jsp:useBean id="pageBean" scope="request" class="com.agileai.hotweb.domain.PageBean"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<%
String curObjType = pageBean.getStringValue("curObjType");
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>活动定义管理</title>
<%@include file="/jsp/inc/resource.inc.jsp"%>
<script src="js/Json.js" type="text/javascript"></script>
<script language="javascript">
function saveActivity(){
	ele('actionType').value="saveActivity";
	if (!validation.isRawChar($('#WFA_CODE').val())){
		writeErrorMsg('编码只能是字母、数字、点或者下划线！');
		return;
	}
	postRequest('form1',{onComplete:function(rspText){
		if (rspText != "fail"){
			var obj = $.parseJSON(rspText);
			var id = obj.id;			
			var name = obj.name;
			parent.setModelText(name);
			parent.PopupBox.closeCurrent();	
			parent.window.focus();
			parent.document.body.focus();			
		}		
	}});	
}

var interceptorBox;
function showInterceptorBox(positionType,interceptorType,interceptorId){
	var title = null;
	var handlerId = null;
	if (!validation.checkNull(interceptorId)){
		title = "编辑拦截器";
		if ('RestInvoker' == interceptorType){
			handlerId = 'WfWebServiceInvokerEdit';	
		}
		else if ('DBOperater' == interceptorType){
			handlerId = 'WfDBOperatorEdit';	
		}
		else if ('FlowLauncher' == interceptorType){
			handlerId = 'WfProcessLauncherEdit';	
		}
		else if ('WatchInvoker' == interceptorType){
			handlerId = 'WfProcessInvokerEdit';	
		}		
	}else{
		title = "新增拦截器";
		handlerId = 'WfInterceptorTypeSelect';
	}
	if (!interceptorBox){
		interceptorBox = new PopupBox('interceptorBox',title,{width:'600px',height:'430px',top:'5px'}); 
	}	
	sendRequest('<%=pageBean.getHandlerURL()%>&actionType=clearSessionParam',{onComplete:function(){
		interceptorBox.sendRequest('index?'+handlerId+'&interceptorType='+interceptorType
								   +'&positionType='+positionType+'&interceptorId='+interceptorId
								   +'&WFA_ID='+$('#WFA_ID').val()+'&WFA_TYPE='+$("#WFA_TYPE").val());		
	}});
}

var forkActivitySelectBox;
function showForkActivitySelectBox(){
	if (!forkActivitySelectBox){
		forkActivitySelectBox = new PopupBox('forkActivitySelectBox',"请选择匹配分支",{width:'500px',height:'350px',top:'5px'}); 
	}	
	var url = "index?WfForkActivitySelect";
	forkActivitySelectBox.sendRequest(url);		
}

function deleteInterceptor(positionType,interceptorId){
	var url = '<%=pageBean.getHandlerURL()%>&actionType=deleteInterceptor&positionType='+positionType+'&interceptorId='+interceptorId+'&WFA_ID='+$('#WFA_ID').val();
	sendRequest(url,{onComplete:function(responseText){
		if ('success' == responseText){
			refreshInterceptor();			
		}
	}});
}

function moveupInterceptor(positionType,interceptorId){
	var url = '<%=pageBean.getHandlerURL()%>&actionType=moveupInterceptor&positionType='+positionType+'&interceptorId='+interceptorId+'&WFA_ID='+$('#WFA_ID').val();
	sendRequest(url,{onComplete:function(responseText){
		if ('success' == responseText){
			refreshInterceptor();			
		}
	}});
}

function movedownInterceptor(positionType,interceptorId){
	var url = '<%=pageBean.getHandlerURL()%>&actionType=movedownInterceptor&positionType='+positionType+'&interceptorId='+interceptorId+'&WFA_ID='+$('#WFA_ID').val();
	sendRequest(url,{onComplete:function(responseText){
		if ('success' == responseText){
			refreshInterceptor();			
		}
	}});
}

function refreshInterceptor(){
	$("#focusTabId").val("Layer1");
	doSubmit({actionType:'refreshInterceptors'});
}
function showSecurityConfig(){
	var url = "index?SecurityAuthorizationConfig&resourceType=Activity&resourceId=<%=pageBean.inputValue("WFA_ID")%>&height=330&randomKey="+Math.random();
	$('#SecurityFrame').attr('src',url);
}
function setForkConfigs(nodeType){
	if ('join' == nodeType){
		var controlType = $("#controlType").val();
		if (controlType == 'OR'){
			$("#matchForkTr").show();
		}else{
			$("#matchForkTr").hide();
		}
	}
}

function closeBox(){
	parent.PopupBox.closeCurrent();
	parent.window.focus();
	parent.document.body.focus();
}
</script>
</head>
<body>
<form action="<%=pageBean.getHandlerURL()%>" name="form1" id="form1" method="post">
<%@include file="/jsp/inc/message.inc.jsp"%>
<div id="__ToolBar__">
<table border="0" cellpadding="0" cellspacing="1">
<tr height="24px;">
   <td onmouseover="onMover(this);" onmouseout="onMout(this);" class="bartdx" align="center" onClick="saveActivity()"><input value="&nbsp;" type="button" class="saveImgBtn" id="saveImgBtn" title="保存" />保存</td>
   <td onmouseover="onMover(this);" onmouseout="onMout(this);" class="bartdx" align="center" onClick="closeBox()"><input value="&nbsp;" type="button" class="closeImgBtn" title="关闭" />关闭</td>
</tr>
</table>
</div>
<div class="photobg1" id="tabHeader">
<div class="newarticle1">基本信息</div>
<%
if ("manual".equals(curObjType) || "audit".equals(curObjType) || "invoke".equals(curObjType)){
%>
<div class="newarticle1">任务设置</div>
<%}%>
<%
if ("manual".equals(curObjType) || "audit".equals(curObjType)){
%>
<div class="newarticle1" onclick="showSecurityConfig()">权限授权</div>
<%}%>
</div>
<div class="photobox newarticlebox" id="Layer0" style="height:420px;">
<table class="detailTable" cellspacing="0" cellpadding="0">
<tr>
	<th width="100" nowrap>编码</th>
	<td><input id="WFA_CODE" name="WFA_CODE" type="text" value="<%=pageBean.inputValue("WFA_CODE")%>" size="24" class="text" />
</td>
</tr>
<tr>
	<th width="100" nowrap>名称</th>
	<td><input id="WFA_NAME" name="WFA_NAME" type="text" value="<%=pageBean.inputValue("WFA_NAME")%>" size="24" class="text" />
</td>
</tr>
<tr>
	<th width="100" nowrap>活动类型</th>
	<td><%=pageBean.selectText("WFA_ACTIVITY_TYPE",pageBean.inputValue("WFA_TYPE"))%><input id="WFA_TYPE" name="WFA_TYPE" type="hidden" value="<%=pageBean.inputValue("WFA_TYPE")%>" />
</td>
</tr>
<%
if ("manual".equals(curObjType) || "audit".equals(curObjType)){
%>
<tr>
	<th width="100" nowrap>业务URL</th>
	<td nowrap="nowrap"><textarea name="WFA_BIZ_URL" cols="70" rows="3" class="text" id="WFA_BIZ_URL" style="word-break: break-all;"><%=pageBean.inputValue("WFA_BIZ_URL")%></textarea><img class="varselecter" src="images/varselecter.png" width="20" height="20" onclick="showVariableBox('WFA_BIZ_URL','primitive')" style="cursor:pointer" /></td>
</tr>
<tr>
	<th width="100" nowrap>移动URL</th>
	<td nowrap="nowrap"><textarea name="WFA_MBIZ_URL" cols="70" rows="3" class="text" id="WFA_MBIZ_URL" style="word-break: break-all;"><%=pageBean.inputValue("WFA_MBIZ_URL")%></textarea><img class="varselecter" src="images/varselecter.png" width="20" height="20" onclick="showVariableBox('WFA_MBIZ_URL','primitive')" style="cursor:pointer" /></td>
</tr>
<%}%>
<%
if ("fork".equals(curObjType) || "join".equals(curObjType)){
%>
<tr>
	<th width="100" nowrap>控制类型</th>
	<td><select name="controlType" id="controlType" onchange="setForkConfigs('<%=curObjType%>');"><%=pageBean.selectValue("WFA_TRANS_TYPE",pageBean.inputValue("controlType")) %></select></td>
</tr>
<%
if ("join".equals(curObjType)){
%>
<tr id="matchForkTr">
	<th width="100" nowrap>匹配分支</th>
	<td><input id="matchedFork" name="matchedFork" type="text" value="<%=pageBean.inputValue("matchedFork")%>" size="24" class="text" />
	<input type="button" class="formbutton" value="选择" onclick="showForkActivitySelectBox()" />
	</td>
</tr>
<script>
$(function(){
	setForkConfigs('join');
});
</script>
<%}%>

<%}%>

<tr>
	<th width="100" nowrap>描述</th>
	<td><textarea name="WFA_DESC" cols="70" rows="3" class="textarea" id="WFA_DESC"><%=pageBean.inputValue("WFA_DESC")%></textarea>
</td>
</tr>
</table>
</div>
<%
if ("manual".equals(curObjType) || "audit".equals(curObjType) || "invoke".equals(curObjType)){
%>
<div class="photobox newarticlebox" id="Layer1" style="height:420px;display:none">
<table border="0" cellpadding="0" cellspacing="0" class="borderTable" style="border-width:0px;">
<tr>
	<th width="100" nowrap class="xborder">
	<%if ("invoke".equals(curObjType)){%>任务列表<%}else{%>前置任务<%}%>
	</th>
	<td>    
<table class="dataTable" cellspacing="0" cellpadding="0" style="width:100%">
<thead id="ec_table_head">
  <tr>
    <th width="40" align="center" nowrap="nowrap">序号</th>
    <th width="100" align="center" nowrap="nowrap">任务类型</th>
    <th width="60%" align="center" nowrap="nowrap">任务名称</th>
    <th width="160" style="text-align:center" nowrap ><input type="button" class="formbutton" name="button" id="button" value="添加" onclick="showInterceptorBox('in','','')" /></th>
  </tr>
</thead>
<%
pageBean.initListAttribute("inInterceptorModelList");
int inInterceptorModelListSize = pageBean.listSize();
if (inInterceptorModelListSize==0){
%>
  <tr>
    <td style="text-align:center" colspan="4">无</td>
  </tr>
<%
}else{ 
for (int i=0;i < inInterceptorModelListSize;i++){
%>
  <tr>
    <td height="24" style="text-align:center"><%=i+1%></td>
    <td height="24">&nbsp;<%=pageBean.inputValue(i,"interceptorName")%></td>
    <td height="24">&nbsp;<%=pageBean.inputValue(i,"interceptorTypeName")%></td>
    <td height="24" style="text-align:center" nowrap>
      <input type="button" class="formbutton" value="编辑" onclick="showInterceptorBox('in','<%=pageBean.inputValue(i,"interceptorType")%>','<%=pageBean.inputValue(i,"interceptorId")%>')" />
      <input type="button" class="formbutton" value="删除" onClick="deleteInterceptor('in','<%=pageBean.inputValue(i,"interceptorId")%>')" />
      <input type="button" class="formbutton" value="上移" <%=pageBean.disabled(i== 0)%> onClick="moveupInterceptor('in','<%=pageBean.inputValue(i,"interceptorId")%>')" />
      <input type="button" class="formbutton" value="下移" <%=pageBean.disabled(i== (inInterceptorModelListSize-1))%> onClick="movedownInterceptor('in','<%=pageBean.inputValue(i,"interceptorId")%>')" />
	</td>
  </tr>
<%}}%>
</table>
	</td>
</tr>

<%
if (!"invoke".equals(curObjType)){
%>
<tr>
	<th width="100" nowrap class="xborder" style="margin-bottom: 0px;">后续任务</th>
	<td>    
<table class="dataTable" cellspacing="0" cellpadding="0" style="width:100%;margin-bottom:0px;">
<thead id="ec_table_head">
  <tr>
    <th width="40" align="center" nowrap="nowrap">序号</th>
    <th width="100" align="center" nowrap="nowrap">任务类型</th>
    <th width="60%" align="center" nowrap="nowrap">任务名称</th>
    <th width="160" style="text-align:center" nowrap ><input type="button" class="formbutton" name="button" id="button" value="添加" onclick="showInterceptorBox('out','','')" /></th>
  </tr>
</thead>
<%
pageBean.initListAttribute("outInterceptorModelList");
int outInterceptorModelListSize = pageBean.listSize();
if (outInterceptorModelListSize==0){
%>
  <tr>
    <td style="text-align:center" colspan="4">无</td>
  </tr>
<%
}else{ 
for (int i=0;i < outInterceptorModelListSize;i++){
%>
  <tr>
    <td height="24" style="text-align:center"><%=i+1%></td>
    <td height="24">&nbsp;<%=pageBean.inputValue(i,"interceptorName")%></td>
    <td height="24">&nbsp;<%=pageBean.inputValue(i,"interceptorTypeName")%></td>
    <td height="24" style="text-align:center" nowrap>
    <input type="button" class="formbutton" value="编辑" onclick="showInterceptorBox('out','<%=pageBean.inputValue(i,"interceptorType")%>','<%=pageBean.inputValue(i,"interceptorId")%>')" />      
    <input type="button" class="formbutton" value="删除" onClick="deleteInterceptor('out','<%=pageBean.inputValue(i,"interceptorId")%>')" />
	<input type="button" class="formbutton" value="上移" <%=pageBean.disabled(i== 0)%> onClick="moveupInterceptor('out','<%=pageBean.inputValue(i,"interceptorId")%>')" />
	<input type="button" class="formbutton" value="下移" <%=pageBean.disabled(i== (outInterceptorModelListSize-1))%> onClick="movedownInterceptor('out','<%=pageBean.inputValue(i,"interceptorId")%>')" />
  </td>
  </tr>
<%}}%>
</table>
</td>
</tr>
<%}%>
</table>
</div>
<%}%>

<%
if ("manual".equals(curObjType) || "audit".equals(curObjType)){
%>
<div class="photobox newarticlebox" id="Layer2" style="height:420px;display:none">
<iframe id="SecurityFrame" src="" width="100%" height="410" frameborder="0" scrolling="no"></iframe>
</div>
<%}%>
<input type="hidden" id="WFA_ID" name="WFA_ID" value="<%=pageBean.inputValue("WFA_ID")%>" />
<input type="hidden" id="WFP_ID" name="WFP_ID" value="<%=pageBean.inputValue("WFP_ID")%>" />
<input type="hidden" name="actionType" id="actionType" value=""/>
<input type="hidden" name="focusTabId" id="focusTabId" value=""/>
<input type="hidden" name="varIndex" id="varIndex" value=""/>
<jsp:include page="/jsp/inc/varselecter.inc.jsp" flush="true" />
</form>
<script language="javascript">
lengthValidators[0].set(36).add("WFA_ID");
lengthValidators[1].set(36).add("WFP_ID");
lengthValidators[2].set(32).add("WFA_CODE");
lengthValidators[3].set(64).add("WFA_NAME");
lengthValidators[4].set(128).add("WFA_DESC");
lengthValidators[5].set(32).add("WFA_TYPE");
lengthValidators[6].set(512).add("WFA_BIZ_URL");
var tab = new Tab('tab','tabHeader','Layer',0);

<%
if (pageBean.isValid(pageBean.inputValue("focusTabId"))){
%>
tab.focus({id:'<%=pageBean.inputValue("focusTabId")%>'});
<%}%>

<%if ("manual".equals(curObjType)){%>
//requiredValidator.add("WFA_BIZ_URL");
<%}%>
</script>
</body>
</html>
<%@include file="/jsp/inc/scripts.inc.jsp"%>
